<template>
	<view class="">
		<view class="application-record" v-if="shops.length">
			<view class="card-list" v-for="item in shops" :key="item.id">
				<view class="card-top">
					<view class="title">{{item.shopName}}</view>
					<view class="time">提交时间：{{item.createTime}}</view>
					<view v-if="item.failReason" class="reason">认证失败原因：{{item.failReason}}</view>
				</view>
				<view class="line"></view>
				<view class="card-bottom">
					<view v-if="item.applied==1" class="card-status">
						<image class="status-icon" v-if="item.authStatus === 0" src="./static/images/pending.png" mode=""></image>
						<image class="status-icon" v-else-if="item.authStatus === 1" src="./static/images/passed.png" mode=""></image>
						<image class="status-icon" v-else-if="item.authStatus === -1" src="./static/images/not-pass.png" mode=""></image>
						<text class="status-text">{{item.authStatus===0?"待认证":(item.authStatus===1?"认证通过":"认证未通过")}}</text>
					</view>
					<view v-else class="card-status">
						<text class="status-text">未申请认证</text>
					</view>
					<view v-if="item.canModify" style="display: flex;">
						<view class="status-btn" @click="goEdit(item)">编辑</view>
						<view class="status-btn" style="margin-left: 20rpx;" @click="delShop(item)">删除</view>
					</view>
				</view>
			</view>
		</view>
		<view class='no-shop' v-if="!shops.length">
			<view class='pictrue' style="margin: 0 auto;">
				<image src='/static/images/no-shop.png'></image>
				<text>暂无记录，快去添加吧!</text>
			</view>
		</view>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import {
		getMyShops,
		delMyShop
	} from '@/api/fsh.js'
	export default {
		data() {
			return {
				shops: [],
				pageNum: 1
			}
		},
		onLoad(options) {
			this.getShops()
		},
		// 滚动到底部
		onReachBottom() {
			if (this.count == this.shops.length) {
				uni.showToast({
					title: '没有更多啦',
					icon: 'none',
					duration: 1000
				});
			} else {
				this.pageNum += 1
				this.getShops()
			}
		},
		methods: {
			getShops() {
				uni.showLoading({
					title: '数据加载中',
				});
				getMyShops(null, this.pageNum).then(res => {
					console.log(res)
					this.count = res.entity.count;
					this.shops = this.shops.concat(res.entity.list)
					uni.hideLoading();
				}).catch(err=>{
					uni.hideLoading();
				})
			},
			// 跳转逻辑
			goEdit(item) {
				let url = `/pages/shop/shop_edit?shopEditType=2&editShopId=${item.id}`;
				uni.navigateTo({
					url: url
				})
			},
			// 删除
			delShop(item) {
				uni.showLoading({
					title: '删除中...',
				});
				delMyShop(item.id).then(res => {
					this.count = res.entity.count;
					this.shops = res.entity.list;
					uni.hideLoading();
				}).catch(err=>{
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {}

	.application-record {
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #F5F5F5;
		padding: 20rpx 30rpx;

		.card-list {
			width: 100%;
			background-color: #fff;
			padding: 20rpx 24rpx;
			margin: 10rpx 20rpx;
			border-radius: 12rpx;

			.card-top {
				height: 140rpx;

				.title {
					font-size: 28rpx;
					font-weight: bold;
					color: #333333;
				}

				.time {
					color: #999999;
					font-size: 24rpx;
					padding: 5rpx 0;
				}

				.reason {
					color: #E93323;
					font-weight: bold;
					font-size: 24rpx;
				}
			}

			.line {
				height: 2rpx;
				margin: 20rpx 0 20rpx 0;
				background-color: #EEEEEE;
			}

			.card-bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #333;

				.card-status {
					display: flex;
					align-items: center;

					.status-icon {
						width: 30rpx;
						height: 30rpx;
						margin: 10rpx;
					}

					.status-text {
						font-size: 28rpx;
						font-weight: 500;
					}
				}

				.status-btn {
					font-size: 26rpx;
					color: #555;
					border: 1px solid #999999;
					padding: 8rpx 32rpx;
					border-radius: 40rpx;
				}
			}
		}

	}

	.no-shop {
		width: 100%;
		background-color: #fff;
		height: 100vh;

		.pictrue {
			display: flex;
			flex-direction: column;
			align-items: center;
			color: $uni-nothing-text;

			image {
				width: 414rpx;
				height: 380rpx;
			}
		}
	}
</style>
